from api.services.db_service import DbService

class BaseModel:
    """所有模型的基类"""
    
    @classmethod
    def get_table_name(cls):
        """获取表名"""
        return cls.__name__.lower() + 's'
    
    @classmethod
    def create(cls, **kwargs):
        """创建记录"""
        return DbService.create(cls.get_table_name(), kwargs)
    
    @classmethod
    def get_by_id(cls, id):
        """根据ID获取记录"""
        return DbService.get_by_id(cls.get_table_name(), id)
    
    @classmethod
    def get_all(cls, where=None, args=None):
        """获取所有记录"""
        return DbService.get_all(cls.get_table_name(), where, args)
    
    @classmethod
    def update(cls, id, **kwargs):
        """更新记录"""
        return DbService.update(cls.get_table_name(), id, kwargs)
    
    @classmethod
    def delete(cls, id):
        """删除记录"""
        return DbService.delete(cls.get_table_name(), id)